package com.xiyucode.yuerinterface.controller;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import com.xiyucode.yuerclientsdk.model.User;
import org.springframework.web.bind.annotation.*;

import static com.xiyucode.yuerinterface.constant.ConstantUtil.NUMBER_LENGTH;

/**
 * 加密接口
 *
 * @author xiyucode
 */
@RestController
@RequestMapping("/encrypted")
public class EncryptedController {

    @PostMapping("/toEncryptedSalt")
    public String toEncrypted(@RequestParam String text, String salt) {
        return SecureUtil.md5(text + salt);
    }

    @PostMapping("/toEncrypted")
    public String toEncrypted(@RequestParam String text) {
        return SecureUtil.md5(text);
    }

    @PostMapping("/supperEncryptedSalt")
    public String toEncrypted(@RequestBody User user,@RequestParam String text, String salt) {
        String str = user.getUsername() + text + salt + "." + RandomUtil.randomNumbers(NUMBER_LENGTH);
        return SecureUtil.md5(str);
    }

}
